//201902104003邵潇漩
package bysj.service;

import bysj.dao.GraduateProjectTypeDao;
import bysj.domain.GraduateProject;
import bysj.domain.GraduateProjectType;
import util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

public final class GraduateProjectTypeService {
	private static GraduateProjectTypeService graduateProjectTypeService = new GraduateProjectTypeService();
	private GraduateProjectTypeDao graduateProjectTypeDao = GraduateProjectTypeDao.getInstance();
	
	private GraduateProjectTypeService(){}
	
	public static GraduateProjectTypeService getInstance(){
		return graduateProjectTypeService;
	}

	public Collection<GraduateProjectType> findAll() throws SQLException {
		return graduateProjectTypeDao.findAll();
	}

	public GraduateProjectType find(Integer id) throws SQLException{
		//获得连接以便完成可能的事务操作
		Connection connection = JdbcHelper.getConn();
		GraduateProjectType graduateProjectType=null;
		//将自动提交设为false,开始事务
		connection.setAutoCommit(false);
		try {
			graduateProjectType=graduateProjectTypeDao.find(id,connection);
			//提交事务
			connection.commit();
		}catch (SQLException e) {
			//回滚事务中所有操作
			connection.rollback();
		} finally {
			//将自动提交设置为true，结束事务
			connection.setAutoCommit(true);
			//关闭连接
			JdbcHelper.close(connection);
		}
		return graduateProjectType;
	}
	
	public boolean update(GraduateProjectType graduateProjectType) throws SQLException{
		return graduateProjectTypeDao.update(graduateProjectType);
	}
	
	public boolean add(GraduateProjectType graduateProjectType) throws SQLException{
		return graduateProjectTypeDao.add(graduateProjectType);
	}

	public boolean delete(Integer id) throws SQLException{
		return graduateProjectTypeDao.delete(id);
	}
	
	//public boolean delete(GraduateProjectType graduateProjectType) throws SQLException{
	//	return graduateProjectTypeDao.delete(graduateProjectType);
	//}
}
